﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties.CApSLPSetLocationsPropertiesCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties;

public class CApSLPSetLocationsPropertiesCmd : TxButtonCommand
{
  private CApSLPSetLocationsPropertiesEnabler _enabler;
  private const string _STRING_TABLE_LOCATION = "DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties.StringTable";
  private ResourceManager _resourceManager;
  private TxForm _setLocationsPropertiesForm;

  public CApSLPSetLocationsPropertiesCmd()
  {
    this._enabler = new CApSLPSetLocationsPropertiesEnabler();
    this._resourceManager = new ResourceManager("DnProcessSimulateCommands.MultiEditingInPathEditor.SetLocationsProperties.StringTable", ((object) this).GetType().Assembly);
  }

  public virtual bool Licensed => TxCommandLicenser.SetLocationsParametersLicense;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this._enabler;

  public virtual string Bitmap
  {
    get => this._resourceManager.GetString("SET_LOCATIONS_PROPERTIES_BITMAP");
  }

  public virtual string Category
  {
    get => this._resourceManager.GetString("SET_LOCATIONS_PROPERTIES_CATEGORY");
  }

  public virtual string Description
  {
    get => this._resourceManager.GetString("SET_LOCATIONS_PROPERTIES_DESCRIPTION");
  }

  public virtual string Name => this._resourceManager.GetString("SET_LOCATIONS_PROPERTIES_NAME");

  public virtual string Tooltip
  {
    get => this._resourceManager.GetString("SET_LOCATIONS_PROPERTIES_TOOLTIP");
  }

  public virtual ITxImage Image
  {
    get => (ITxImage) TxImageManager.GetImageByKey("SetLocationsProperties");
  }

  public virtual void Execute(object cmdParams)
  {
    if (!this._enabler.Enable || this._setLocationsPropertiesForm != null || !this.ShouldShowDialog())
      return;
    this._setLocationsPropertiesForm = (TxForm) new CCUiSLPSetLocationsPropertiesDlg();
    ((Form) this._setLocationsPropertiesForm).FormClosed += new FormClosedEventHandler(this._setLocationsPropertiesForm_FormClosed);
    TxApplication.ApplicationEvents.Exiting += new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
    ((Control) this._setLocationsPropertiesForm).Show();
  }

  private void ApplicationEvents_Exiting(object sender, TxApplication_ExitingEventArgs args)
  {
    if (this._setLocationsPropertiesForm == null)
      return;
    ((Form) this._setLocationsPropertiesForm).Close();
  }

  private void _setLocationsPropertiesForm_FormClosed(object sender, FormClosedEventArgs e)
  {
    if (this._setLocationsPropertiesForm != null)
      ((Form) this._setLocationsPropertiesForm).FormClosed -= new FormClosedEventHandler(this._setLocationsPropertiesForm_FormClosed);
    this._setLocationsPropertiesForm = (TxForm) null;
    TxApplication.ApplicationEvents.Exiting -= new TxApplication_ExitingEventHandler(this.ApplicationEvents_Exiting);
  }

  private bool ShouldShowDialog()
  {
    if (!CApSLPSetLocationsPropertiesEnabler.ShouldCheckLocationForCanBeModified())
      return true;
    bool flag = true;
    TxObjectList<ITxRoboticLocationOperation> editableLocations = (TxObjectList<ITxRoboticLocationOperation>) null;
    TxObjectList<ITxRoboticLocationOperation> readOnlyLocations = (TxObjectList<ITxRoboticLocationOperation>) null;
    CApSLPSetLocationsPropertiesEnabler.ExtractLocationsFromSelection(out editableLocations, out readOnlyLocations);
    if (readOnlyLocations != null && ((Collection<ITxRoboticLocationOperation>) readOnlyLocations).Count > 0)
    {
      string str = this._resourceManager.GetString("SET_LOCATIONS_PROPERTIES_NAME");
      if (editableLocations != null && ((Collection<ITxRoboticLocationOperation>) editableLocations).Count > 0)
      {
        flag = TxMessageBox.Show(this._resourceManager.GetString("SELECTION_CONTAINS_SOME_READ_ONLY_LOCATIONS"), str, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
      }
      else
      {
        TxMessageBox.Show(this._resourceManager.GetString("SELECTION_CONTAINS_JUST_READ_ONLY_LOCATIONS"), str, MessageBoxButtons.OK, MessageBoxIcon.Hand);
        flag = false;
      }
    }
    return flag;
  }
}
